package com.michael.aop.cglib;

import com.michael.aop.Driver;
import com.michael.aop.Passenger;
import com.michael.aop.annotation.AnnotationInfo;
import com.michael.aop.annotation.Log;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.*;

@Aspect
public class PointcutAspectJTest {


    @Pointcut("target(driver)")
    public void pointcut(Driver driver){

    }
    /**
     * target的测试: target(Type or Id) 之ID
     */
    @Before("pointcut(driver)")
    public void targetId(Driver driver){
        System.out.println("@Before **** target(Type or Id) 之ID --" + driver.getName());
    }
    /**
     * target的测试: target(Type or Id) 之Type
     */
    @After("target(com.michael.aop.Driver)")
    public void targetType(){
        System.out.println("@After target(Type or Id) 之Type --");
    }
    /**
     * this的测试: this(Type or Id) 之ID
     */
    @Before("this(driver)")
    public void thisId(Driver driver){
        //不能直接调用driver里面的对象，应该driver是代理对象，如果调用，会陷入无限循环
//        System.out.println(" this(Type or Id) 之ID " + driver.getName());
        System.out.println("@Before this(Type or Id) 之ID ");
    }
    /**
     * this的测试: this(Type or Id) 之Type
     */
    @Before("this(com.michael.aop.Driver)")
    public void thisType(){
        System.out.println("@Before this(Type or Id) 之Type ");
    }
    /**
     * within的测试: within(TypePattern)
     */
    @Before("within(com.michael.aop..*)")
    public void within_1(){
        System.out.println("@Before within(com.michael.aop..*) ");
    }
    /**
     * within的测试: within(TypePattern)
     */
    @Before("within(com.michael..*)")
    public void within_2(){
        System.out.println("@Before within(com.michael..*) ");
    }
    /**
     * within的测试: within(TypePattern)
     */
    @Before("within(com.michael.aop.C1Driver)")
    public void within_3(){
        System.out.println("@Before within(com.michael.aop.C1Driver) ");
    }
    /**
     * within的测试: within(TypePattern)
     */
    @Before("within(com..*)")
    public void within_4(){
        System.out.println("@Before within(com..*) ");
    }
    /**
     * within的测试: within(TypePattern)
     */
    @Before("within(com..aop)")
    public void within_5(){
        System.out.println("@Before within(com..aop) ");
    }
    /**
     * within的测试: within(TypePattern)
     */
    @Before("within(com..aop.*)")
    public void within_6(){
        System.out.println("@Before within(com..aop.*) ");
    }
    /**
     * within的测试: within(TypePattern)
     */
    @Before("within(com..aop.C1Dri*)")
    public void within_7(){
        System.out.println("@Before within(com..aop.C1Dri*) ");
    }
    /**
     * within的测试: within(TypePattern)
     */
    @Before("within(com..aop.C1Dri+)")
    public void within_8(){
        System.out.println("@Before within(com..aop.C1Dri+) ");
    }

    /**
     * @target的测试： @target(Type or Id) 之Id
     */
    @Before("@target(component)")
    public void annotationTargetId(AnnotationInfo component){
        System.out.println("@Before @target(Type or Id) 之Id"+component);
    }
    /**
     * @target的测试： @target(Type or Id) 之Type
     */
    @Before("@target(org.springframework.stereotype.Component)")
    public void annotationTargetType(){
        System.out.println("@Before @target(Type or Id) 之Type");
    }
    /**
     * @target的测试： @Within(Type or Id) 之Id
     */
    @Before("@within(component)")
    public void annotationWithinTargetId(AnnotationInfo component){
        System.out.println("@Before @within(Type or Id) 之Id"+component);
    }
    /**
     * @target的测试： @Within(Type or Id) 之Type
     */
    @Before("@within(org.springframework.stereotype.Component)")
    public void annotationWithinType(){
        System.out.println("@Before @within(org.springframework.stereotype.Component)");
    }
    @Before("execution(com..* com.michael..pass*(..))")
    public void execution(){
        System.out.println("@Before(\"execution(com..* com.michael..pass*(..))\")");
    }
    @Before("execution(com..* com.michael..*(..))")
    public void execution_1(){
        System.out.println("@Before(\"execution(com..* com.michael..*(..))\")");
    }
    /**
     * @annotation的测试：@annotation(Type Or Id)之Id
     */
    @Before("@annotation(log)")
    public void annotationWithId(JoinPoint joinPoint, Log log){
        System.out.println("@Before @annotation(log)");
    }
    /**
     * @annotation的测试：@annotation(Type Or Id)之 Type
     */
    @After(value = "@annotation(com.michael.aop.annotation.Log)")
    public void annotationWithType(){
        System.out.println("@Before @annotation(com.michael.aop.annotation.Log)");
    }

    /**
     * args测试：args(Type Or Id,....)之 Id
     */
    @After(value = "args(passenger)")
    public void argsId(Passenger passenger){
        System.out.println("@Before args(passenger)");
    }
    /**
     * args测试：args(Type Or Id,....)之 Type
     */
    @After(value = "args(com.michael.aop.Passenger)")
    public void argsType(){
        System.out.println("@After args(com.michael.aop.Passenger)");
    }
    /**
     * @args测试：@args(Type Or Id,....)之 Type
     */
    @After(value = "@args(org.springframework.stereotype.Component)")
    public void annotationArgsType(){
        System.out.println("@After @args(org.springframework.stereotype.Component)");
    }
    /**
     * @args测试：@args(Type Or Id,....)之 Id
     */
    @After(value = "@args(component)")
    public void annotationArgsId(AnnotationInfo component){
        System.out.println("@After @args(component)"+component);
    }
}
